package org.heart.springsecurity.controller;

import org.heart.springsecurity.pojo.Users;
import org.heart.springsecurity.result.ApiResponse;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.UUID;

@RestController
@RequestMapping("api/v1/user")
@CrossOrigin("*")
public class UsersController {
    private static final ArrayList<Users> users = new ArrayList<>();

    @PostMapping("getUser")
    public String getUser() {
        return ApiResponse.ListIsEmpty(users);
    }

    @PostMapping("addUser")
    public String addUser(@RequestParam("username") String username) {
        users.add(new Users().setUsersId(UUID.randomUUID().toString())
                .setUsername(username)
                .setPassword(passwordEncoder())
                .setPhone("1000000"));

        return ApiResponse.success();
    }

    @GetMapping("passwordEncoder")
    public String passwordEncoder() {
        return PasswordEncoderFactories.createDelegatingPasswordEncoder().encode("123456");
    }



}
